package com.bjesc_b2c.app.appraiset.mvp.view.activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.bjesc_b2c.app.appraiset.R;
import com.bjesc_b2c.app.appraiset.RequestAndResultCode;
import com.bjesc_b2c.app.appraiset.adapter.MoveOrderAdapter;
import com.bjesc_b2c.app.appraiset.adapter.SalesAdapter;
import com.bjesc_b2c.app.appraiset.base.BaseActivity;
import com.bjesc_b2c.app.appraiset.http.IApiActivityRequest;
import com.bjesc_b2c.app.appraiset.mvp.presenter.AppraiserPresenter;
import com.orhanobut.logger.Logger;
import com.rxretrofit_build.util.MapUtil;

import java.util.List;

import app.pinggushi.bjesc.com.baserecyclerview.adapter.MultiItemTypeAdapter;
import butterknife.Bind;
import butterknife.OnClick;
import master_bean.AppraiserBean;
import rxretrofit_base.model.ShowType;
import rxretrofit_base.model.TokenBean;
import rxretrofit_base.net.BaseSubscriber;
import rxretrofit_base.net.RxRequest;

/**
 * Created by yidong on 2017/8/24.
 */

public class SalesStaffActivity extends BaseActivity implements MultiItemTypeAdapter.OnItemClickListener,MoveOrderAdapter.OnContentFillListener{
    @Bind(R.id.recycler_view)
    RecyclerView recyclerView;
    @Bind(R.id.tv_title)
    TextView titleTv;
    private SalesAdapter adapter;
    private List<AppraiserBean> appraiserList;
    private String dispatchId;
    private String appraId;
    private String content;
    private AppraiserPresenter presenter;
    private EditText contentEdit;
    private Intent intent;
    @Override
    protected int getLayout() {
        return R.layout.layout_header_reccycler;
    }

    @Override
    protected void initEventAndData() {
        titleTv.setText("B2C专员列表");
        intent = new Intent();
    }

    @Override
    protected void createPresenter() {
        getB2cList();
    }

    private void initViews() {
        adapter = new SalesAdapter(this, R.layout.layout_item_carfrom_one, appraiserList);
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
        String salesName = adapter.getDatas().get(position).getName();
        String salesId = adapter.getDatas().get(position).getId();
        intent.putExtra("salesName", salesName);
        intent.putExtra("salesId", salesId);
        setResult(RequestAndResultCode.BasicActivityToSelectCarBrandActivity, intent);
        finish();
    }
    @Override
    public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
        return false;
    }

    @Override
    public void onContentFill(int position, String price) {
        Logger.d(position +  "======" +price);
        content = price;
    }

    @OnClick({R.id.iv_return})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_return:
                finish();
                break;
        }
    }
    private void getB2cList(){
        RxRequest.request(ShowType.DISMISS, RxRequest.getClient(mContext, new MapUtil().build()).create(IApiActivityRequest.class).getAllAppraiser(),
                new BaseSubscriber<TokenBean<List<AppraiserBean>>>(mContext) {
                    @Override
                    public void onSuccess(TokenBean<List<AppraiserBean>> o) {
                       if (o.getData() != null){
                           appraiserList = o.getData();
                           initViews();
                       }
                    }

                    @Override
                    public void onFailure(Throwable e) {
                        cancelLoading();
                    }

                    @Override
                    public void onStart() {
                        showLoading();
                    }

                    @Override
                    public void onCompleted() {
                        cancelLoading();
                    }
                });
    }
}
